﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CFSystem.JXC.BLL;
using CFSystem.JXC.Model;
namespace CFSystem.JXC.BasisInfo
{
    public partial class FrmVendorSetting : Form
    {
        public FrmVendorSetting()
        {
            InitializeComponent();
            LoadAllVendors();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FrmVendorDetailsEdit frmVendorEdit = new FrmVendorDetailsEdit();
            frmVendorEdit.SyncDataGridView += new FrmVendorDetailsEdit.UpdateDataBinding(frmVendorEdit_SyncDataGridView);
            frmVendorEdit.StartPosition = FormStartPosition.CenterParent;
            frmVendorEdit.ShowDialog();
        }
        private void frmVendorEdit_SyncDataGridView()
        {
            LoadAllVendors();
        }
        private void LoadAllVendors()
        {
            Vendor vendorBLL = new Vendor();
            IList<VendorInfo> vendors = vendorBLL.GetVendors();
            dgVvendors.DataSource = vendors;
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            
            FrmVendorDetailsEdit frmVendorEdit = new FrmVendorDetailsEdit(Convert.ToInt32(dgVvendors.SelectedRows[0].Cells[0].Value));
            frmVendorEdit.SyncDataGridView += new FrmVendorDetailsEdit.UpdateDataBinding(frmVendorEdit_SyncDataGridView);
            frmVendorEdit.StartPosition = FormStartPosition.CenterParent;
            frmVendorEdit.ShowDialog();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            Vendor vd = new Vendor();
            vd.Delete(Convert.ToInt32(dgVvendors.SelectedRows[0].Cells[0].Value));
            LoadAllVendors();
        }
    }
}
